﻿using nanhua.BookStore.Entitys.OrderAggregate;
using nanhua.BookStore.Entitys.ProductAggregate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Services;
using Volo.Abp.Guids;
using Volo.Abp.Threading;

namespace nanhua.BookStore.DomainServices
{
    public class OrderManager:DomainService
    {
        IProductRepository _productRepository;
        IGuidGenerator _guidGenerator;
        public OrderManager(IProductRepository productRepository, IGuidGenerator guidGenerator)
        {
            this._productRepository = productRepository;
            this._guidGenerator = guidGenerator;
        }

        public OrderDetail CreateOrderDetail(string productCode,decimal price)
        {
            if (price < 0)
            {
                throw new BusinessException("order:productPriceLessZore");
            }
            if (!_productRepository.IsExistByProductCode(productCode))
            {
                throw new BusinessException("order:productCodeNotExist");
            }
            return new OrderDetail(_guidGenerator.Create(), productCode, price);
        }


    }
}
